<?php
if(!defined('INDEX')){
	exit('Access Denied');
}
//订单认领
$pagesize=20;
$sdate='2015-01-01';
$page = $_GET['page'];
$q    =trim( $_GET['q'] );

if ( WJT==1&&!$q ) {
	$tmp  =explode( '-', PLUGIN_QUERY );
	$q    =trim( $tmp[1] );
	$page =trim( $tmp[2] );
	unset( $tmp );
}
$pstyle     =$plugin_data['pstyle'];
$page_arr   =array( 'q'=>$q );
$is_orderid =false;
/*判断是否是订单号，一般没有这么长的整数搜索*/
if ( strlen( $q )===15&&is_numeric( $q ) ) {
	$is_orderid =true;
}

if ( $pstyle<1 ) {$pstyle='';}

$page   =!$page?'1':intval( $page );
$frmnum =( $page-1 )*$pagesize;
$where  ='';
$where1 ='';
if ( TAOTYPE==1 ) {//有api用户不用status字段
	$where1 =' and status>1';
}

if ( !$q ) {
	$time  ='"'.$plugin_data['sdate'].' 00:00:00"';
	$where ='checked=0 and create_time>'.$time.$where1;
	$total =$duoduo->count( 'tradelist', $where );
	$dd    =$duoduo->select_all( 'tradelist', '*', $where.' order by id desc limit '.$frmnum.','.$pagesize, false );

}elseif (isset ($_GET['q']) && is_numeric($_GET['q']) && $_GET['q']>0) {
	if ( TAOTYPE==1 ) {
		$where = ' and trade_id_former = "' . $q . '"';
	}
	else {
		$where = ' and trade_id = "' . $q . '"';
	}
	$where ='checked=0'.$where.$where1;
	$total =$duoduo->count( 'tradelist', $where );
	$dd    =$duoduo->select_all( 'tradelist', '*', $where.' order by create_time,id desc limit '.$frmnum.','.$pagesize, false );
}else {
	$where ='checked=0 and item_title like "%'.$q.'%"'.$where1;
	$total =$duoduo->count( 'tradelist', $where );
	$dd    =$duoduo->select_all( 'tradelist', '*', $where.' order by create_time,id desc limit '.$frmnum.','.$pagesize, false );
}

if ( !function_exists( 'dingdan_page' ) ) {
	function dingdan_page( $totle, $displaypg = 20, $url = '', $wjt=0, $wjtmodel=0, $shownum = 1, $showlvtao = 7 ) {
		if ( $wjtmodel==0 ) {
			$page = $_GET['p']?(int)$_GET['p']:1;
		}
		else {
			if ( $wjt ==1 ) {
				$tmp  =explode( '-', PLUGIN_QUERY );
				$page =$tmp[2];unset( $tmp );
			}else {
				$page = $_GET['page'];
			}
			$page =!$page?'1':intval( $page );
		}
		if ( $wjt ==0 ) {
			if ( $wjtmodel ==0 ) {
				$url .='&page';
			}
			else {
				$url .='&page';
			}
		}
		elseif ( $wjt ==1 ) {
			$url =preg_replace( '/\.html$/', '', $url );
		}

		//页码计算：
		$lastpg     = ceil( $totle / $displaypg ); //最后页，也是总页数
		$page       = min( $lastpg, $page );
		$prepg      = $page -1; //上一页
		$nextpg     = ( $page == $lastpg ? 0 : $page +1 ); //下一页
		$firstcount = ( $page -1 ) * $displaypg;

		//如果只有一页则跳出函数：
		if ( $lastpg <= 1 )
			return false;

		if ( $wjt == '1' ) {
			if ( $prepg )
				if ( $wjtmodel ==0 ) {
					$pagenav .= "<a href='$url/$prepg' class='pg-prev'>上一页</a>";
				}
			else {
				$pagenav .= "<a href='$url-$prepg.html' class='pg-prev'>上一页</a>";
			}
			else
				$pagenav .= "<span class='pg-prev'>上一页</span>";

		} else {
			if ( $prepg )
				$pagenav .= "<a href='$url=$prepg' class='pg-prev'>上一页</a>";
			else
				$pagenav .= "<span class='pg-prev'>上一页</span>";
		}
		if ( $shownum == 1 ) {
			$o = $showlvtao; //中间页码表总长度，为奇数
			$u = ceil( $o / 2 ); //根据$o计算单侧页码宽度$u
			$f = $page - $u; //根据当前页$currentPage和单侧宽度$u计算出第一页的起始数字
			//str_replace('{p}',,$fn)//替换格式
			if ( $f < 0 ) {
				$f = 0;
			} //当第一页小于0时，赋值为0
			$n = $lastpg; //总页数,20页
			if ( $n < 1 ) {
				$n = 1;
			} //当总数小于1时，赋值为1
			if ( $page == 1 ) {
				$pagenav .= '<span>1</span>';
			} else {
				if ( $wjt == '1' ) {
					if ( $wjtmodel==0 ) {
						$pagenav .= "<a href='$url/1'>1</a>";
					}
					else {
						$pagenav .= "<a href='$url-1.html'>1</a>";
					}
				} else {
					$pagenav .= "<a href='$url=1'>1</a>";
				}
			}
			///////////////////////////////////////
			for ( $i = 1; $i <= $o; $i++ ) {
				if ( $n <= 1 ) {
					break;
				} //当总页数为1时
				$c = $f + $i; //从第$c开始累加计算
				if ( $i == 1 && $c > 2 ) {
					$pagenav .= '<i>...</i>';
				}
				if ( $c == 1 ) {
					continue;
				}
				if ( $c == $n ) {
					break;
				}
				if ( $c == $page ) {
					$pagenav .= '<span>' . $page . '</span>';
				} else {
					if ( $wjt == '1' ) {
						if ( $wjtmodel==0 ) {
							$pagenav .= "<a href='$url/$c'>$c</a>";
						}
						else {
							$pagenav .= "<a href='$url-$c.html'>$c</a>";
						}
					} else {
						$pagenav .= "<a href='$url=$c'>$c</a>";
					}
				}
				if ( $i == $o && $c < $n -1 ) {
					$pagenav .= '<i>...</i>';
				}
				if ( $i > $n ) {
					break;
				} //当总页数小于页码表长度时
			}
			if ( $page == $n && $n != 1 ) {
				$pagenav .= '<span>' . $n . '</span>';
			} else {
				if ( $wjt == '1' ) {
					if ( $wjtmodel==0 ) {
						$pagenav .= "<a href='$url/$n'>$n</a>";
					}
					else {
						$pagenav .= "<a href='$url-$n.html'>$n</a>";
					}
				} else {
					$pagenav .= "<a href='$url=$n'>$n</a>";
				}
			}
		}

		if ( $wjt == '1' ) {
			if ( $nextpg )
				if ( $wjtmodel==0 ) {
					$pagenav .= "<a href='$url/$nextpg' class='pg-next'>下一页</a>";
				}
			else {
				$pagenav .= "<a href='$url-$nextpg.html' class='pg-next'>下一页</a>";
			}
			else
				$pagenav .= "<span class='pg-next'>下一页</span>";
			;
		} else {
			if ( $nextpg )
				$pagenav .= "<a href='$url=$nextpg' class='pg-next'>下一页</a>";
			else
				$pagenav .= "<span class='pg-next'>下一页</span>";
			;
		}
		return $pagenav;
	}
}
$webtitle=$webset['title'].'订单认领-找回订单';
include(TPLPATH.'/inc/header_2.tpl.php');
?>
<div class="yingdao" align="center">
  <p><b>认领订单</b><a href="javascript:;" onclick="history.back()" title="返回" class="left"></a> <a href='<?=wap_l('tao','tao')?>' title="搜索" class="right"></a> </p></div>  
    <div class="admin_xfl">
                    <ul>
            <li><a href="<?=wap_l('user','order',array('do'=>'taobao'))?>" <?php if($do=='taobao'){?>class="on"<?php }?>>淘宝订单</a> </li>
            <li><a href="<?=wap_l('user','order',array('do'=>'mall'))?>"<?php if($do=='mall'){?>class="on"<?php }?>>商城订单</a> </li>
            <li><a href="<?=wap_l('user','dingdan')?>"<?php if($act=='dingdan'){?>class="on"<?php }?>>认领订单</a> </li>
                    </ul>
              	</div>
   <div class="wap-index" style="background:#fff">
       
   <div class="p15">
<div class="sm"><font color="#FF0000">注意：</font>以下订单已成交，由于用户未登录本站，或操作错误，系统无法识别购买用户。请在下面认领属于您的订单以便找回您的返利！</div>
<div class="mainindex">
<div class="admin_searchx">
<form action="m/index.php">
<input type="hidden" name="mod" value="<?=MOD?>">
<input type="hidden" name="act" value="<?=ACT?>">
<input class="admin_searchx_input1" type="text" id="q" name="q" value="<?=$q?$q:'输入商品名称或订单号'?>" placeholder="输入商品名称或订单号" onclick="this.value=''"> <input class="tijiao" type="submit" value="查找订单">
</form></div>
 </div> </div>
 <?php foreach($dd as $row){?>  
  <div  class="dingdan">
            <div  class="dingdan1">
			<div  class="lb1"><font color="#f60">下单时间：<?=date('Y-m-d',strtotime($row['create_time']))?></font> &nbsp;&nbsp;￥<?=$row['real_pay_fee']!='0.00'?$row['real_pay_fee'].'元':'--'?></div>
                    <div  class="lb0"><a href="<?=wap_l('tao','view',array('iid'=>$row['num_iid']))?>"><?=$row['item_title']?></a></div>
                  </div> 
                   <div  class="dingdan2"> <a href="<?=wap_l('user','dingdan2',array('id'=>$row['id']))?>">我要认领</a> </div> 
                        </div> 
<?php }?> 
  </div> 
<div class="megas513"> 
 <?=dingdan_page($total,$pagesize,p('m','dingdan',$page_arr),WJT,true)?>
</div>
</div>  

<?php include(TPLPATH.'/inc/footer.tpl.php');?>